<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>vuepress-plugin-redirect | VuePress Community</title>
    <meta name="description" content="Community supported ecosystem for VuePress">
    <link rel="icon" href="/logo/600x600.png">
  <meta name="theme-color" content="#3eaf7c">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="msapplication-TileColor" content="#000000">
    <link rel="preload" href="/assets/css/0.styles.bde909c2.css" as="style"><link rel="preload" href="/assets/js/app.83cb924b.js" as="script"><link rel="preload" href="/assets/js/2.96e68d5e.js" as="script"><link rel="preload" href="/assets/js/3.e29c89cb.js" as="script"><link rel="preload" href="/assets/js/5.1cd3ace7.js" as="script"><link rel="prefetch" href="/assets/js/10.8fab5e9f.js"><link rel="prefetch" href="/assets/js/11.9e66637f.js"><link rel="prefetch" href="/assets/js/12.23a476a6.js"><link rel="prefetch" href="/assets/js/13.cbd5d914.js"><link rel="prefetch" href="/assets/js/14.78046e0f.js"><link rel="prefetch" href="/assets/js/15.15f2d0bd.js"><link rel="prefetch" href="/assets/js/16.c749a5c9.js"><link rel="prefetch" href="/assets/js/17.f54b2102.js"><link rel="prefetch" href="/assets/js/18.0da93583.js"><link rel="prefetch" href="/assets/js/19.7ec782b6.js"><link rel="prefetch" href="/assets/js/20.2ac16953.js"><link rel="prefetch" href="/assets/js/21.059dc84f.js"><link rel="prefetch" href="/assets/js/22.b80a1088.js"><link rel="prefetch" href="/assets/js/23.14ac2e9b.js"><link rel="prefetch" href="/assets/js/24.645912bb.js"><link rel="prefetch" href="/assets/js/25.d99ab9d1.js"><link rel="prefetch" href="/assets/js/26.439ac2ad.js"><link rel="prefetch" href="/assets/js/27.7a5265ba.js"><link rel="prefetch" href="/assets/js/28.68a7bdf2.js"><link rel="prefetch" href="/assets/js/29.83d3986f.js"><link rel="prefetch" href="/assets/js/30.44036763.js"><link rel="prefetch" href="/assets/js/31.4e32f3c0.js"><link rel="prefetch" href="/assets/js/32.5c64f4c8.js"><link rel="prefetch" href="/assets/js/33.bc6170ff.js"><link rel="prefetch" href="/assets/js/34.2a1877c0.js"><link rel="prefetch" href="/assets/js/35.6a0693b1.js"><link rel="prefetch" href="/assets/js/36.036cfdd9.js"><link rel="prefetch" href="/assets/js/37.5c4deb98.js"><link rel="prefetch" href="/assets/js/4.a98f17db.js"><link rel="prefetch" href="/assets/js/6.b1866fbb.js"><link rel="prefetch" href="/assets/js/7.757f3a25.js"><link rel="prefetch" href="/assets/js/8.e5910e9d.js"><link rel="prefetch" href="/assets/js/9.68190a5d.js">
    <link rel="stylesheet" href="/assets/css/0.styles.bde909c2.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/en/" class="home-link router-link-active"><!----> <span class="site-name">VuePress Community</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">Languages</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/en/plugins/redirect/" class="nav-link router-link-exact-active router-link-active">English</a></li><li class="dropdown-item"><!----> <a href="/zh/plugins/redirect/" class="nav-link">简体中文</a></li></ul></div></div> <a href="https://github.com/vuepress/vuepress.github.io" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">Languages</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/en/plugins/redirect/" class="nav-link router-link-exact-active router-link-active">English</a></li><li class="dropdown-item"><!----> <a href="/zh/plugins/redirect/" class="nav-link">简体中文</a></li></ul></div></div> <a href="https://github.com/vuepress/vuepress.github.io" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>Plugins</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/en/plugins/container/" class="sidebar-link">vuepress-plugin-container</a></li><li><a href="/en/plugins/copyright/" class="sidebar-link">vuepress-plugin-copyright</a></li><li><a href="/en/plugins/clean-urls/" class="sidebar-link">vuepress-plugin-clean-urls</a></li><li><a href="/en/plugins/dehydrate/" class="sidebar-link">vuepress-plugin-dehydrate</a></li><li><a href="/en/plugins/git-log/" class="sidebar-link">vuepress-plugin-git-log</a></li><li><a href="/en/plugins/mathjax/" class="sidebar-link">vuepress-plugin-mathjax</a></li><li><a href="/en/plugins/medium-zoom/" class="sidebar-link">vuepress-plugin-medium-zoom</a></li><li><a href="/en/plugins/migrate/" class="sidebar-link">vuepress-plugin-migrate</a></li><li><a href="/en/plugins/named-chunks/" class="sidebar-link">vuepress-plugin-named-chunks</a></li><li><a href="/en/plugins/nprogress/" class="sidebar-link">vuepress-plugin-nprogress</a></li><li><a href="/en/plugins/redirect/" class="active sidebar-link">vuepress-plugin-redirect</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/en/plugins/redirect/#usage" class="sidebar-link">Usage</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/en/plugins/redirect/#global-installation" class="sidebar-link">Global Installation</a></li><li class="sidebar-sub-header"><a href="/en/plugins/redirect/#local-installation" class="sidebar-link">Local Installation</a></li><li class="sidebar-sub-header"><a href="/en/plugins/redirect/#add-to-config-js" class="sidebar-link">Add to config.js</a></li></ul></li><li class="sidebar-sub-header"><a href="/en/plugins/redirect/#configurations" class="sidebar-link">Configurations</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/en/plugins/redirect/#locales" class="sidebar-link">locales</a></li><li class="sidebar-sub-header"><a href="/en/plugins/redirect/#redirectors" class="sidebar-link">redirectors</a></li><li class="sidebar-sub-header"><a href="/en/plugins/redirect/#redirector-base" class="sidebar-link">redirector.base</a></li><li class="sidebar-sub-header"><a href="/en/plugins/redirect/#redirector-storage" class="sidebar-link">redirector.storage</a></li><li class="sidebar-sub-header"><a href="/en/plugins/redirect/#redirector-alternative" class="sidebar-link">redirector.alternative</a></li></ul></li></ul></li><li><a href="/en/plugins/serve/" class="sidebar-link">vuepress-plugin-serve</a></li><li><a href="/en/plugins/zooming/" class="sidebar-link">vuepress-plugin-zooming</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Tools</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="vuepress-plugin-redirect"><a href="#vuepress-plugin-redirect" aria-hidden="true" class="header-anchor">#</a> vuepress-plugin-redirect <a rel="noopener noreferrer" target="_blank" title="vuepress/vuepress-plugin-redirect" href="https://github.com/vuepress/vuepress-plugin-redirect" class="github-link"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 28 28"><path d="M14 0C6.27 0 0 6.43 0 14.36c0 6.34 4.01 11.72 9.57 13.62.7.13.96-.31.96-.69 0-.34-.01-1.24-.02-2.44-3.89.87-4.72-1.92-4.72-1.92-.64-1.66-1.55-2.1-1.55-2.1-1.27-.89.1-.87.1-.87 1.4.1 2.14 1.48 2.14 1.48 1.25 2.19 3.28 1.56 4.07 1.19.13-.93.49-1.56.89-1.92-3.11-.36-6.38-1.59-6.38-7.09 0-1.57.55-2.85 1.44-3.85-.14-.36-.62-1.82.14-3.8 0 0 1.18-.39 3.85 1.47a12.8 12.8 0 0 1 3.5-.48c1.19.01 2.39.16 3.5.48 2.67-1.86 3.85-1.47 3.85-1.47.76 1.98.28 3.44.14 3.8.9 1 1.44 2.28 1.44 3.85 0 5.51-3.27 6.73-6.39 7.08.5.44.95 1.32.95 2.66 0 1.92-.02 3.47-.02 3.94 0 .38.25.83.96.69C23.99 26.07 28 20.7 28 14.36 28 6.43 21.73 0 14 0z" fill-rule="evenodd" clip-rule="evenodd"></path></svg></a></h1> <p>VuePress has a built-in <a href="https://v1.vuepress.vuejs.org/en/guide/i18n.html" target="_blank" rel="noopener noreferrer">i18n system<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>, but you must provide a default language, otherwise you will only get a 404 if you try to access <code>/</code> directly. However, providing a default language often means a less friendly project structure (because the files in the default language are one level lower than others), and we sometimes want our website to keep <code>/</code> for a more intelligent redirection (e.g. determines that the language used by the user based on <code>navigator.language</code> and automatically redirects to the corresponding page). <code>vuepress-plugin-redirect</code> is such a plugin that handles automatic redirections. Of course, its capacity is not limited to automatic redirecting of the language, because you can redirect any page to its subpages via a custom redirector.</p> <!----> <h2 id="usage"><a href="#usage" aria-hidden="true" class="header-anchor">#</a> Usage</h2> <h3 id="global-installation"><a href="#global-installation" aria-hidden="true" class="header-anchor">#</a> Global Installation</h3> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">npm</span> <span class="token function">install</span> -g vuepress-plugin-redirect
<span class="token comment"># OR</span>
<span class="token function">yarn</span> global <span class="token function">add</span> vuepress-plugin-redirect
</code></pre></div><h3 id="local-installation"><a href="#local-installation" aria-hidden="true" class="header-anchor">#</a> Local Installation</h3> <div class="language-bash extra-class"><pre class="language-bash"><code><span class="token function">npm</span> <span class="token function">install</span> vuepress-plugin-redirect
<span class="token comment"># OR</span>
<span class="token function">yarn</span> <span class="token function">add</span> vuepress-plugin-redirect
</code></pre></div><h3 id="add-to-config-js"><a href="#add-to-config-js" aria-hidden="true" class="header-anchor">#</a> Add to <code>config.js</code></h3> <div class="language-js extra-class"><pre class="language-js"><code>module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
  plugins<span class="token punctuation">:</span> <span class="token punctuation">[</span>
    <span class="token punctuation">[</span><span class="token string">'redirect'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
      <span class="token comment">// provide i18n redirection</span>
      <span class="token comment">// it will automatically redirect `/foo/bar/` to `/:locale/foo/bar/` if exists</span>
      locales<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
  <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre></div><p>or</p> <div class="language-js extra-class"><pre class="language-js"><code>module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
  plugins<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    redirect<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      redirectors<span class="token punctuation">:</span> <span class="token punctuation">[</span>
        <span class="token comment">// customize your redirectors</span>
        <span class="token punctuation">{</span>
          base<span class="token punctuation">:</span> <span class="token string">'/my-plugins/'</span><span class="token punctuation">,</span> <span class="token comment">// automatically redirect `/my-plugins/` to a subpage</span>
          storage<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token comment">// save the result of the last visit to `localStorage` for the next redirect</span>
          alternative<span class="token punctuation">:</span> <span class="token punctuation">[</span>
            <span class="token comment">// provide an alternate list</span>
            <span class="token comment">// if no page was matched, you will get a &quot;404 not found&quot;</span>
            <span class="token string">'mathjax'</span><span class="token punctuation">,</span> <span class="token comment">// equivalent to `/my-plugins/mathjax/`</span>
            <span class="token string">'migrate'</span><span class="token punctuation">,</span>
            <span class="token string">'pangu'</span><span class="token punctuation">,</span>
            <span class="token string">'redirect'</span><span class="token punctuation">,</span>
            <span class="token string">'serve'</span><span class="token punctuation">,</span>
          <span class="token punctuation">]</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">]</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><h2 id="configurations"><a href="#configurations" aria-hidden="true" class="header-anchor">#</a> Configurations</h2> <h3 id="locales"><a href="#locales" aria-hidden="true" class="header-anchor">#</a> locales</h3> <ul><li><strong>type:</strong> <code>boolean</code></li> <li><strong>default:</strong> <code>false</code></li></ul> <p>Whether to provide i18n redirection.</p> <h3 id="redirectors"><a href="#redirectors" aria-hidden="true" class="header-anchor">#</a> redirectors</h3> <ul><li><strong>type:</strong> <code>Redirector[]</code></li> <li><strong>default:</strong> <code>[]</code></li></ul> <p>A list of custom redirectors.</p> <h3 id="redirector-base"><a href="#redirector-base" aria-hidden="true" class="header-anchor">#</a> redirector.base</h3> <ul><li><strong>type:</strong> <code>string</code></li> <li><strong>default:</strong> <code>'/'</code></li></ul> <p>Base URL to be redirected.</p> <h3 id="redirector-storage"><a href="#redirector-storage" aria-hidden="true" class="header-anchor">#</a> redirector.storage</h3> <ul><li><strong>type:</strong> <code>boolean | string | Storage</code></li> <li><strong>default:</strong> <code>false</code></li></ul> <p>Decide how the results of the redirect are stored. If set to <code>string</code>, it corresponds to the key of <code>localStorage</code>. If it is an object, you must include the following two methods:</p> <ul><li><code>get(redirector: Redirector): string</code></li> <li><code>set(value: string, redirector: Redirector): void</code></li></ul> <p>A simple <code>storage</code> object is provided below for your reference:</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">const</span> storage <span class="token operator">=</span> <span class="token punctuation">{</span>
  <span class="token keyword">get</span><span class="token punctuation">(</span><span class="token punctuation">{</span> base <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">typeof</span> localStorage <span class="token operator">===</span> <span class="token string">'undefined'</span><span class="token punctuation">)</span> <span class="token keyword">return</span> <span class="token keyword">null</span>
    <span class="token keyword">return</span> localStorage<span class="token punctuation">.</span><span class="token function">getItem</span><span class="token punctuation">(</span><span class="token string">'redirect:'</span> <span class="token operator">+</span> base<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token keyword">set</span><span class="token punctuation">(</span>value<span class="token punctuation">,</span> <span class="token punctuation">{</span> base <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">typeof</span> localStorage <span class="token operator">===</span> <span class="token string">'undefined'</span><span class="token punctuation">)</span> <span class="token keyword">return</span>
    localStorage<span class="token punctuation">.</span><span class="token function">setItem</span><span class="token punctuation">(</span><span class="token string">'redirect:'</span> <span class="token operator">+</span> base<span class="token punctuation">,</span> value<span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>
</code></pre></div><h3 id="redirector-alternative"><a href="#redirector-alternative" aria-hidden="true" class="header-anchor">#</a> redirector.alternative</h3> <ul><li><strong>type:</strong> <code>string | string[] | ((rel: string) =&gt; string | string[])</code></li> <li><strong>default:</strong> <code>undefined</code></li></ul> <p>An alternate list of redirects. A requested URL will be devided into two parts, <code>base</code> and <code>rel</code>, and <code>alternative</code> will be inserted between them. If it is a function, <code>rel</code> will be passed as a parameter. All the results obtained will be tried in sequence, and the first existing page will be taken for redirection.</p></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/vuepress/vuepress.github.io/edit/master/docs/en/plugins/redirect.md" target="_blank" rel="noopener noreferrer">Edit this page on GitHub</a> <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></div> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">4/4/2019, 5:55:51 PM</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/en/plugins/nprogress/" class="prev">
          vuepress-plugin-nprogress
        </a></span> <span class="next"><a href="/en/plugins/serve/">
          vuepress-plugin-serve
        </a>
        →
      </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.83cb924b.js" defer></script><script src="/assets/js/2.96e68d5e.js" defer></script><script src="/assets/js/3.e29c89cb.js" defer></script><script src="/assets/js/5.1cd3ace7.js" defer></script>
  </body>
</html>
